package com.banmoon.spring_boot_logger.task;

import com.banmoon.spring_boot_logger.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class LoggerTask {
	
	@Autowired
	private UserMapper userMapper;
	
	@Scheduled(cron = "0/30 * * * * ?")
	public void logTask(){
		// 日志级别，由低到高，trace < debug < info < warn < error
		log.trace("TRACE");
		log.debug("DEBUG日志");
		log.info("INFO日志");
		log.warn("WARN日志");
		log.error("ERROR日志");
	}
	
	/**
	 * 定时去查询数据库表
	 */
	@Scheduled(cron = "10 * * * * ?")
	public void dbDemonstration(){
		log.info("=====================");
		int count = userMapper.countByExample(null);
		log.info("用户条数：{}", count);
		log.info("=====================");
	}
	
}
